package database.bean;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Type;

import enumTypes.Civility;


@Entity
@Table(name = "user", uniqueConstraints = {@UniqueConstraint(columnNames={"uid"})})
public class User {
		
	@Id
	@GeneratedValue
	@Column(name = "uid")
	private int user_uid;
	
	@Column(name = "last_name", nullable = false)
	private String user_lastname;
	
	@Column(name = "name", nullable = false)
	private String user_name;
	
	@Enumerated(EnumType.STRING)
	@Column(name = "civil", nullable = false)
	private Civility user_civil;
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="card")
    private AuthCardData card;
	
	@Column(name = "biometric_data", columnDefinition = "BINARY(255)", nullable = true)
	@Type(type="org.hibernate.type.BinaryType")
	private byte[] user_biometric_data;
	
	/**
	 * Constructeur vide.
	 */
	public User() {}
 
	/**
	 * Créer un nouveau User.
	 * @param lastname : nom de l'utilisateur
	 * @param name : prénom de l'utilisateur
	 * @param mail : email de l'utilisateur
	 * @param civil : civilité de l'utilisateur
	 * @param seed : sel de generation du mot de passe de l'utilisateur
	 */
	public User(String lastname, String name, Civility civil) {
		this.user_lastname = lastname;
		this.user_name = name;
		this.user_civil = civil;
	}
	
	public int getUser_uid() { return user_uid; }
	public void setUser_uid(int user_uid) { this.user_uid = user_uid; }

	public String getUser_name() { return user_name; }
	public void setUser_name(String user_name) { this.user_name = user_name; }

	public String getUser_lastname() { return user_lastname; }
	public void setUser_lastname(String user_lastname) { this.user_lastname = user_lastname; }
	
	public Civility getUser_civil() { return user_civil;	}
	public void setUser_civil(Civility user_civil) { this.user_civil = user_civil;	}
	
	public AuthCardData getCard() {	return card;	}
	public void setCard(AuthCardData card) {	this.card = card;	}
	
	public byte[] getUser_biometric_data() { return user_biometric_data; }
	public void setUser_biometric_data(byte[] user_biometric_data) { this.user_biometric_data = user_biometric_data; }

	@Override
	public String toString() { return this.user_name+" "+this.user_name; }

}
